#ifndef __SSLCONNECTION_H__
#define __SSLCONNECTION_H__

#define SSLCONNECTION_CLIENT_RESEEDING "SSLCONNECTION_CLIENT_RESEEDING"
#define SSLCONNECTION_SERVER_RESEEDING "SSLCONNECTION_SERVER_RESEEDING"
class SSLConnection : public Connection
{
public:
	// ctor
	SSLConnection( struct sockaddr_in src_addr );
	
	// dtor
	~SSLConnection();
	
	// init ssl
	int InitSSL( ctr_drbg_context* p_ctr_drbg, x509_cert* p_ca_certificate, x509_cert* p_server_certificate, rsa_context* p_server_privatekey );

protected:
	// do outgoing connect (proxy->server)
	virtual int DoConnect();

	// virtual send/recv function (calls the real send/recv function)
	virtual int DoSend( const int sock, const char* data, const int len );
	virtual int DoRecv( const int sock, char* buf, const int len );
	
	///////////////////////////////////////////////////////////////////////////////////////
	// for outgoing connection
	///////////////////////////////////////////////////////////////////////////////////////
	x509_cert* m_p_outgoing_ca_certificate;
    entropy_context m_outgoing_entropy;
    ctr_drbg_context m_outgoing_ctr_drbg;
	ssl_context m_outgoing_ssl;
	ssl_session m_outgoing_ssn;
	///////////////////////////////////////////////////////////////////////////////////////
	
	///////////////////////////////////////////////////////////////////////////////////////
	// for incoming connection
	///////////////////////////////////////////////////////////////////////////////////////	
	// session handling required by polarssl
	static ssl_session *m_incoming_s_list_1st;
	static int GetSession( ssl_context *ssl );
	static int SetSession( ssl_context *ssl );

	// ssl info
	ctr_drbg_context m_incoming_ctr_drbg;
	ssl_context m_incoming_ssl;
	ssl_session m_incoming_ssn;

	// static const DH vars
	static const char* m_incoming_dhm_P;
	static const char* m_incoming_dhm_G;

	// static instance count vars
	static unsigned int m_incoming_instance_count;

	// mutex to protect some static vars
	static pthread_mutex_t m_incoming_mutex;
	///////////////////////////////////////////////////////////////////////////////////////	
};

#endif /* __SSLCONNECTION_H__ */
